﻿using System;

namespace Alfa.Units {
	public struct Celsius : ITemperatureUnit, IComparable<Celsius>, IEquatable<Celsius> {
		private decimal degrees;
		public Celsius(decimal Degrees) {
			this.degrees = Degrees;
		}

		public static explicit operator Fahrenheit(Celsius celsius) {
			return new Fahrenheit(celsius.degrees * 9m / 5m + 32);
		}

		public static explicit operator Kelvin(Celsius celsius) {
			return new Kelvin(celsius.degrees + 273.15m);
		}

		public static explicit operator Rankine(Celsius celsius) {
			return new Rankine((celsius.degrees + 273.15m) * 9m / 5m);
		}

		public static implicit operator decimal(Celsius celsius) {
			return celsius.degrees;
		}

		decimal ITemperatureUnit.Degrees { get { return this.degrees; } }

		string ITemperatureUnit.Symbol { get { return "°C"; } }

		public int CompareTo(object obj) {
			if (obj is ITemperatureUnit) {
				return ((ITemperatureUnit)this).CompareTo((ITemperatureUnit)obj);
			} else
				throw new InvalidCastException(obj.GetType( ).Name + " does not implement ITemperatureUnit");
		}

		int IComparable<ITemperatureUnit>.CompareTo(ITemperatureUnit other) {
			return this.degrees.CompareTo(((Celsius)other).degrees);
		}

		bool IEquatable<ITemperatureUnit>.Equals(ITemperatureUnit other) {
			return this.degrees.Equals(((Celsius)other).degrees);
		}

		int IComparable<Celsius>.CompareTo(Celsius other) {
			return this.degrees.CompareTo(other.degrees);
		}

		bool IEquatable<Celsius>.Equals(Celsius other) {
			return this.degrees.Equals(other.degrees);
		}
	}
}
